package com.spring.gll.controller;

import com.spring.gll.dao.TeacherDao;
import com.spring.gll.model.Teacher;
import com.spring.gll.test.MybatisTeacherTest;
import com.spring.gll.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

@Controller
@RequestMapping("/teacher")
public class TeacherComtroller {
    @RequestMapping("/view")
    public String view(){
        return "teacher";
    }
    @RequestMapping("/add")
    public String add(String name,Integer age,Date date) throws Exception {
        SqlSession ss2 = MybatisUtil.getSqlSession();
//        ss2.insert("")
        TeacherDao tm = ss2.getMapper(TeacherDao.class);
        Teacher t=new Teacher();
        t.setName(name);
        t.setAge(age);
        t.setBirthday(date);
        tm.add(t);
        ss2.commit();
        ss2.close();
        return "Success";
    }

    @RequestMapping("/add1")
    public String add1(String name,Integer age) throws Exception {
        MybatisTeacherTest.add(name,age);
        return "Success";
    }

}
